package com.fin.zw.aiqas.entity;


import com.fin.zw.aiqas.enums.Status;
import lombok.Data;
import org.hibernate.annotations.Table;

import javax.persistence.*;
import java.util.Objects;
import java.util.Set;

@Entity
@Table(appliesTo = "rule_info", comment = "规则信息")
@Data
public class RuleInfo extends BaseEntity {
    @Column(columnDefinition = "bigint(32) COMMENT '规则分类id'")
    private Long ruleTypeId;
    @Column(columnDefinition = "varchar(100) COMMENT '规则分类名称'")
    private String ruleTypeName;
    @Column(columnDefinition = "varchar(100) COMMENT '规则名称'")
    private String ruleName;
    @Column(columnDefinition = "varchar(200) COMMENT '质检点关系表达式(质检点id质检的逻辑运算)'")
    private String relation;
    @Column(columnDefinition = "varchar(64) COMMENT '检测角色'")
    private String checkRole;
    @Column(columnDefinition = "varchar(20) COMMENT '状态'")
    @Enumerated(EnumType.STRING)
    private Status states;
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "rule_formula", joinColumns = @JoinColumn(name = "rule_id"), inverseJoinColumns = @JoinColumn(name = "formula_id"))
    private Set<FormulaInfo> formulaInfos;
    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "rule_scenes_id", referencedColumnName = "id", columnDefinition = "bigint(64) COMMENT '应用场景ID'")
    private ScenesInfo scenesInfo;

    @Column(columnDefinition = "varchar(100) COMMENT '等级'")
    private String ruleLevel;

    @Column(columnDefinition = "varchar(100) COMMENT '编码'")
    private String ruleCode;


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        RuleInfo ruleInfo = (RuleInfo) o;
        return ruleTypeId.equals(ruleInfo.ruleTypeId) &&
                ruleTypeName.equals(ruleInfo.ruleTypeName) &&
                ruleName.equals(ruleInfo.ruleName) &&
                relation.equals(ruleInfo.relation) &&
                checkRole.equals(ruleInfo.checkRole) &&
                states == ruleInfo.states &&
                formulaInfos.equals(ruleInfo.formulaInfos) &&
                scenesInfo.equals(ruleInfo.scenesInfo);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), ruleTypeId, ruleTypeName, ruleName, relation, checkRole, states, formulaInfos, scenesInfo);
    }

    @Override
    public String toString() {
        return "RuleInfo{" +
                "ruleTypeId=" + ruleTypeId +
                ", ruleTypeName='" + ruleTypeName + '\'' +
                ", ruleName='" + ruleName + '\'' +
                ", relation='" + relation + '\'' +
                ", checkRole='" + checkRole + '\'' +
                ", states=" + states +
                ", formulaInfos=" + formulaInfos +
                ", scenesInfo=" + scenesInfo +
                '}';
    }
}
